package com.phantasy.loaders
{
	import flash.system.ApplicationDomain;
	import flash.utils.Dictionary;

	/**
	 *资源池 
	 * @author Liseen
	 * 
	 */	
	public class ResourcePool
	{
		private static var sources:Dictionary = new Dictionary();
		
		public function ResourcePool()
		{
			
		}
		/**
		 *添加到资源池中 
		 * @param key		键
		 * @param data		值
		 * 
		 */				
		public static function add(key:String, data:*):void
		{
			sources[key] = data;
		}
		/**
		 *从资源池中获取 
		 * @param key		键
		 * @return 
		 * 
		 */		
		public static function get(key:String):Object
		{
			return sources[key];
		}
		/**
		 *从资源池移除 
		 * @param key
		 * @return 		移除掉的数据
		 * 
		 */		
		public static function remove(key:String):Object
		{
			var data:* = get(key);
			delete sources[key];
			return data;
		}
		/**
		 *资源池中是否有数据 
		 * @param key
		 * @return 
		 * 
		 */		
		public static function hasResource(key:String):Boolean
		{
			return !(sources[key] == null);
		}
		/**
		 *获取类 
		 * @param key			键
		 * @param className		类
		 * @return 
		 * 
		 */		
		public static function getClass(key:String, className:String):Object
		{
			var appDomain:ApplicationDomain = sources[key];
			if (appDomain && appDomain.hasDefinition(className))
			{
				return appDomain.getDefinition(className);
			}
			return null;
		}
		/**
		 *资源池销毁 
		 * 
		 */		
		public static function dispose():void
		{
			sources = null;
		}
	}
}